package com.hejielife.immutable3;

/**
 * 2019年8月2日 上午11:09:32
 * 
 * @author hejielife
 * @despribe 不可变演示
 */
public class Main2 {
	public static void main(String[] args) {
		MutablePerson mutable = new MutablePerson("start", "start");
		new CrackerThread2(mutable).start();
		new CrackerThread2(mutable).start();
		new CrackerThread2(mutable).start();
		for (int i = 0; true; i++) {
			mutable.setPerson("" + i, "" + i);
		}
	}
}

class CrackerThread2 extends Thread {
	private final MutablePerson mutable;

	public CrackerThread2(MutablePerson mutable) {
		this.mutable = mutable;
	}

	public void run() {
		while (true) {
			ImmutablePerson immutable = new ImmutablePerson(mutable);
			if (!immutable.getName().equals(immutable.getAddress())) {
				System.out.println(currentThread().getName() + " ***** BROKEN ***** " + immutable);
			}
		}
	}
}
